home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Virtual User tools / SPEC S&L v.1.0.1 / Libraries / Select.Lib < prev    next >
Encoding:
Text File  |  1993-12-17  |  10.9 KB  |  303 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        Select.Lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
  9. #
  10. #    Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #     <1.0.3>     12/2/93    KTA        PointSelect() now reports that it performs a click.
  19. #        <1+>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  20. #
  21. # ****************************************************************************
  22. #
  23.  
  24. ########################################################################
  25. #                            External libraries 
  26. #=======================================================================
  27. Libraries "UserInterface.Lib";
  28.  
  29. #########################################################################
  30. #                            SelectModule.vu
  31. #========================================================================
  32. # Description:    This module contains VU code for selecting items.
  33. #                All of the Tasks in this module assume that the select
  34. #                tool has already been selected.  The library Tasks in
  35. #                this module are grouped in the following logical order:
  36. #
  37. #                SelectIt(ProcID,PtorRect)
  38. #                PointSelect(Pt,RelToWindow)
  39. #                RectSelect(Rect,RelToWindow)
  40. #                HereToStartSelect()
  41. #                HereToEndSelect()
  42. #                SelectAll()
  43. #
  44. #     Copyright Apple Computer, Inc. 1985-1990
  45. #    All rights reserved
  46. #
  47. #========================================================================
  48. # History:
  49. #
  50. #########################################################################
  51.  
  52.  
  53. #########################################################################
  54. #                            SelectIt(ProcID,PtorRect)
  55. #========================================================================
  56. # Author:            Su Quek (x48884)
  57. #
  58. # Description:        This routine performs multiple selection tests :
  59. #
  60. #                    #1    Selects a point.
  61. #                    #2    Selects everything within a rectangle.
  62. #                    #3    Selects everything from the current position to the 
  63. #                        top of the file.
  64. #                    #4    Selects everything from the current position to the
  65. #                        bottom of the file.
  66. #                    #5    Selects the entire file, i.e. everything from the
  67. #                        top of the file to the bottom.
  68. #
  69. # Parameters:        ProcID - holds the procedure number
  70. #                    PtorRect - holds Pt or Rect coordinates
  71. #
  72. # Returns:            0 - encountered an input error. ProcID not one of the choices or
  73. #                        format of the PtorRect has an incorrect number of elements.
  74. #
  75. # Examples:            SelectIt(3,PtorRect)
  76. #
  77. # Assumptions:        Ruler is not shown
  78. #========================================================================
  79. # History:
  80. #
  81. #########################################################################
  82. TASK SelectIt(ProcID,PtorRect) begin
  83.  
  84. # Point is a list of 2 numbers which gives the x-y coordinates of the point
  85. # Rect is a list of 4 numbers which gives the left, top, right and bottom coordinates of the rect
  86.  
  87.     if (card(PtorRect) = 4) begin         # PtorRect is a list of 4 numbers
  88.         xcoord := PtorRect[1];            # just for this test, take first 2 numbers as the point coords.
  89.         ycoord := PtorRect[2];
  90.         Point:= {xcoord,ycoord};
  91.         Rect := PtorRect;
  92.     end;
  93.     else if (not (card(PtorRect) = 2) or (card(PtorRect) = 4)) begin        # PtorRect not a Point or a Rect
  94.         println 'PtorRect must be either a list of 2 numbers (in the case of a point) or';
  95.         println ' a list of 4 numbers (in the case of a rectangle)';
  96.         return (0);
  97.     end;
  98.     
  99.     # Select a Task according to the ProcID
  100.     if (ProcID = 1) begin
  101.         PointSelect (Point);                
  102.     end;
  103.     else if (ProcID = 2) begin
  104.         RectSelect (Rect);                       
  105.     end;
  106.     else if (ProcID = 3) begin
  107.         HereToStartSelect ();
  108.     end;
  109.     else if (ProcID = 4) begin
  110.         HereToEndSelect ();
  111.     end;
  112.     else if (ProcID = 5) begin
  113.         SelectAll ();
  114.     end;
  115.     else begin
  116.         println ProcID, ' is not one of the choices';    
  117.         return (0);
  118.     end;
  119. end;
  120.  
  121. #########################################################################
  122. #            PointSelect (pPointList,pRelToWindow, pSpecifier)
  123. #========================================================================
  124. # Author:            SMQ
  125. # Description:        This routine moves the mouse to the location specified
  126. #                    by pPointList and clicks to select the point. 
  127. # Parameters:        pPointList - List - holds the x-y coordinates of the point
  128. #                    pRelToWindow - 1 - coords are relative to the window
  129. #                                  0 - coords are absolutes, with respect 
  130. #                                        to the screen.
  131. #                    pSpecifier - Enables caller to specify the window the move 
  132. #                                 will be relative to. (0 = document window)
  133. # Returns:            what MoveRelativeToWindow() or MoveMouse() return
  134. # Examples:            PointSelect ({120,100},1, 0)
  135. # Assumptions:        
  136. #========================================================================
  137. # History:
  138. # KTA    12/1/93    Changed calls to MoveRelativeToWindow(), MoveMouse() so they
  139. #                can handle logging the click (bug # 1121663)
  140. # KTA    12/1/93 Added pSpecifier input parameter and return value and changed
  141. #                the name of the paramters.
  142. #########################################################################
  143. TASK PointSelect (pPointList,pRelToWindow := 1, pSpecifier := 1) 
  144. begin
  145.     returnVal := 0;                # Init ReturnVal
  146.     if (pRelToWindow)            # Relative To window
  147.         returnVal := MoveRelativeToWindow (pPointList[1],pPointList[2],pSpecifier,2);
  148.     else                        # Absolute coordinates
  149.         returnVal := MoveMouse (pPointList[1],pPointList[2],1,2);
  150.     
  151.     return(returnVal);        
  152. end;
  153.  
  154. #########################################################################
  155. #                    RectSelect (Rect,RelToWindow)
  156. #========================================================================
  157. # Author:            SMQ
  158. # Description:        This routine selects the rectangle specified by Rect.
  159. #                    It moves the mouse to the location specified by the
  160. #                    first 2 elements in Rect and everything up to the 
  161. #                    location specified by the next 2 elements.
  162. # Parameters:        Rect - holds the left, top, right and bottom 
  163. #                            coordinates of the rect.
  164. #                    RelToWindow - 1 - coords are relative to the window
  165. #                                  0 - coords are absolutes, with respect 
  166. #                                        to the screen.
  167. # Returns:            Nothing
  168. # Examples:            RectSelect (Rect,1)
  169. # Assumptions:        Ruler is not shown
  170. #========================================================================
  171. # History:
  172. #
  173. #########################################################################
  174. TASK RectSelect (Rect,RelToWindow := 1) begin
  175.     prev_speed := mouseSpeed(5);            # slow down the mouse and save previous mouse speed
  176.     if (RelToWindow = 1) begin
  177.         MoveRelativeToWIndow (Rect[1],Rect[2],1);
  178.         click;
  179.         MoveMouse (Rect[3]-Rect[1],Rect[4]-Rect[2],0,1);
  180.     end;
  181.     else begin                                # Relative to screen as opposed to window
  182.         MoveMouse (Rect[1],Rect[2],1,0);
  183.         click;
  184.         MoveMouse (Rect[3],Rect[4],1,1);
  185.     end;
  186.     mouseSpeed(prev_speed);                    # reset the mouse speed to original
  187. end;
  188.  
  189. #########################################################################
  190. #                            HereToStartSelect()
  191. #========================================================================
  192. # Author:            SMQ
  193. # Description:        This routine selects everything from the current 
  194. #                    position to the start (Top) of the file.
  195. # Parameters:        None
  196. # Returns:            Nothing
  197. # Examples:            HereToStartSelect()
  198. # Assumptions:        Ruler is not shown, coordinates used are relative 
  199. #                    to the window, as opposed to the screen.
  200. #========================================================================
  201. # History:
  202. #
  203. #########################################################################
  204. TASK HereToStartSelect() begin
  205.     ScrollBarList := GetVHScrollBars();        # Save current position of scrollbar
  206.     Vertical := ScrollBarList[1].s;
  207.     
  208.     Vertical_X := Vertical[1];
  209.     Vertical_Y := Vertical[2];
  210.  
  211.     ScrollWindow('V',0,1);                    # Scroll to the top of file
  212.     
  213.     pressKey k:{ shiftKey };                # Select from current position to top of file
  214.     MoveRelativeToWindow (5,30,1);
  215.     click;
  216.     releaseKey k:{ shiftKey };
  217.     
  218.     ScrollWindow('V',Vertical_X,Vertical_Y);    # Scroll back to original position
  219. end;
  220.  
  221. #########################################################################
  222. #                            HereToEndSelect()
  223. #========================================================================
  224. # Author:            SMQ
  225. # Description:        This routine selects everything from the current 
  226. #                    position to the end (Bottom) of the file.
  227. # Parameters:        None
  228. # Returns:            Nothing
  229. # Examples:            HereToEndSelect()
  230. # Assumptions:        Ruler is not shown, coordinates used are relative 
  231. #                    to the window, as opposed to the screen.
  232. #========================================================================
  233. # History:
  234. #
  235. #########################################################################
  236. TASK HereToEndSelect() begin
  237.     ScrollBarList := GetVHScrollBars();            # Save current position of scrollbar
  238.     Vertical := ScrollBarList[1].s;
  239.     
  240.     Vertical_X := Vertical[1];
  241.     Vertical_Y := Vertical[2];
  242.     
  243.     ScrollWindow('V',1,1);                        # Scroll to the bottom of file
  244.     
  245.     pressKey k:{ shiftKey };                    # Select from current position to bottom of file
  246.     match [window o:1 r:?Rect];
  247.     MoveRelativeToWindow (Rect[3]-Rect[1]-20,Rect[4]-Rect[2]-30,1);
  248.     click;
  249.     releaseKey k:{ shiftKey };
  250.     
  251.     ScrollWindow('V',Vertical_X,Vertical_Y);    # Scroll back to original position
  252. end;
  253.  
  254. #########################################################################
  255. #                            SelectAll()
  256. #========================================================================
  257. # Author:            SMQ
  258. # Description:        This routine selects everything from the top of the
  259. #                    frontmost window to the bottom.
  260. # Parameters:        None
  261. # Returns:            Nothing
  262. # Examples:            SelectAll()
  263. # Assumptions:        Ruler is not shown, coordinates used are relative 
  264. #                    to the window, as opposed to the screen.
  265. #========================================================================
  266. # History:
  267. #
  268. #########################################################################
  269. TASK SelectAll() begin
  270.  
  271.     # see if Select All menu item is there - if so, use it
  272.     theMenuItem := match [menuItem t:'Select All']!;
  273.     if (theMenuItem) begin
  274.         if (theMenuItem.e) begin
  275.             theMenuName := theMenuItem.m;
  276.             theMenuName := theMenuName.t;
  277.             if (SelectMenuItem('Select All',theMenuName))
  278.                 return(1);    # just return to abort routine
  279.         end;
  280.     end;
  281.     
  282.     # if we get to here, there was no 'Select All' menu item or it couldn't
  283.     # be selected - at this point, do it manually.
  284.     ScrollBarList := GetVHScrollBars();            # Save current position of scrollbar
  285.     Vertical := ScrollBarList[1].s;
  286.     
  287.     Vertical_X := Vertical[1];
  288.     Vertical_Y := Vertical[2];
  289.     
  290.     ScrollWindow('V',0,1);                        # Scroll to the top of file
  291.     MoveRelativeToWindow (5,30,1);
  292.     click;
  293.     ScrollWindow('V',1,1);                        # Scroll to the bottom of file
  294.     
  295.     pressKey k:{ shiftKey };                    # Select from top to bottom of file
  296.     match [window o:1 r:?Rect];
  297.     MoveRelativeToWindow (Rect[3]-Rect[1]-20,Rect[4]-Rect[2]-30,1);
  298.     click;
  299.     releaseKey k:{ shiftKey };
  300.     
  301.     ScrollWindow('V',Vertical_X,Vertical_Y);    # Scroll back to original position
  302. end;
  303.